package com.siyougame.weixin.config;

import com.siyougame.system.api.SysDictDataApiService;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @Author: lvliangjun
 * @Date: 2024/5/23 8:55
 */
@Configuration
@EnableConfigurationProperties(WxMpProperties.class)
public class WxMpConfiguration {


    @Autowired
    private SysDictDataApiService sysDictDataApiService;

    private final StringRedisTemplate stringRedisTemplate;
    private final WxMpProperties properties;

    @Autowired
    public WxMpConfiguration(WxMpProperties properties,StringRedisTemplate stringRedisTemplate) {
        this.properties = properties;
        this.stringRedisTemplate = stringRedisTemplate;
    }

 ;
    //    static String corpid = "wp-719DgAAy9Y7e5xDMmLf48VBLM1jUg";
//    static String secret = "C37Utx4cYlWHl04JP_g0Y7MUGXQ6NCwxBnW-24QAbpY";
//    static Integer agentid = 1000029;
    @Bean
    public WxMpService wxMpService() {
        WxMpService wxCpService = new WxMpServiceImpl();

        wxCpService.setWxMpConfigStorage(wxCpConfigStorage());
        return wxCpService;
    }


    public WxMpConfigStorage wxCpConfigStorage() {
        RedisTemplateWxRedisOps redisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
        WxMpRedisConfigImpl wxMpConfigStorage = new WxMpRedisConfigImpl(redisOps,"weixin");
        wxMpConfigStorage.setAppId(properties.getAppId());
        wxMpConfigStorage.setSecret(properties.getAppSecret());
        return wxMpConfigStorage;
    }
}
